/*
 * stackitem.cpp
 *
 *  Created on: 10.10.2011
 *      Author: duke
 */

#include <iostream>
#include <vector>
#include <stdlib.h>
#include "stackitem.h"
#include "edge.h"

using namespace std;

stackitem::stackitem(int index, vector<edge> edges) {
	this->index = index;
	this->edges = edges;
}

int stackitem::getIndex() {
	return this->index;
}

void stackitem::setIndex(int index) {
	this->index = index;
}

vector<edge> stackitem::getEdges(int color) {
	vector<edge> temp;
	for (vector<edge>::iterator it = this->edges.begin(); it
			!= this->edges.end(); ++it) {
		if (it->getColor() == color)
			temp.push_back(*it);
	}
	return temp;
}

vector<edge> stackitem::getAllEdges() {
	return this->edges;
}

void stackitem::setEdgeColor(int index, int color) {
	this->edges.at(index).setColor(color);
}

int stackitem::getEdgeColor(int index) {
	return this->edges.at(index).getColor();
}

void stackitem::print() {
	cout << "----------------------------------" << endl;
	for (vector<edge>::iterator it = this->edges.begin(); it
			!= this->edges.end(); ++it) {
		it->print();
	}
}

//						   <------edge1------> <------edge2------> .....
//	|# of edges|act. index|node1|node2|color12|node1|node2|color12|.....|node1|node2|color12|
int * stackitem::getArray() {
	int j = 0;
	int array_size = 2 + this->edges.size() * 3;
	int *temp = new int[array_size];
	temp[0] = this->edges.size();
	temp[1] = this->index;
	for (int i = 2; i < array_size - 2; i++, j++) {
		temp[i++] = this->edges.at(j).getNode1();
		temp[i++] = this->edges.at(j).getNode2();
		temp[i] = this->edges.at(j).getColor();
	}
	this->edge_array = temp;
	return temp;
}

void stackitem::printArray() {
	cout << endl;
	cout << this->edge_array[0] << " " << this->edge_array[1] << " ";
	for (int i = 2; i < (2 + 3 * (edges.size())); i += 3) {
		cout << this->edge_array[i] << this->edge_array[i + 1]
				<< this->edge_array[i + 2] << " ";
	}
	cout << endl;
}
